/**
 * Created by wenchuan on 2018/5/10.
 */
define(function () {

    var self,
        app = win.app,
        others = {
            ischecked: '0',
            countAmount: 0
        },
        subOrders = [],
        pageParameters
    ;

    function setCountAmount() {
        var c = 0;
        subOrders.forEach(function (v) {

            c += (Number(v.GWBK003) * Number(v.GWBK004));

        });
        others.countAmount = c;
    }

    var QzsjGwcmsg = app.Module.extend({

        init: function () {
            self = this;

            self._super({
                _readyBefore: function () {
                    pageParameters = app.pageParameters['qzsjgwc_page'];
                    var items = pageParameters.items;
                    items.forEach(function (p1, p2, p3) {
                        var _p1 = app.cloneJSON(p1);
                        delete _p1.details;
                        //_p1.ischecked = '1';
                        p1.details.forEach(function (p10, p20, p30) {
                            subOrders.push(app.extend(p10, _p1));
                        });
                    });
                }
            }, win);
        },
        _lazy: function () {
            this._super();
            new Vue({
                el: app.getByid(doc, 'scroll1'),
                data: {
                    items: subOrders
                },
                watch: {
                    items: {
                        handler: function (val, oldVal) {
                            setCountAmount();
                        },
                        deep: true
                    }
                },
                methods: {}
            });

            new Vue({
                el: app.getByid(doc, 'contentFooter'),
                data: others,
                methods: {}
            });
            setCountAmount();

            mui('.mui-scroll-wrapper').scroll({
                deceleration: 0.0005
            });
        },
        _ready: function () {
            Vue.component('qzsjgwcwzd-listitem', {
                template: app.getByid(doc, 'cartitem2-template'),
                props: {
                    model: Array
                },
                methods: {
                    showDetail: function (val) {
                        val.GWAP100_1 = val.GWBK004;
                        app.openPage({
                            src: "gwcxd/qzsj-classes-info" + (val.status == 'Z' ? '-msg' : '') + ".html",
                            argsKey: 'classesinfo_page',
                            args: {
                                order: val,
                                cb: function () {

                                }
                            }
                        });
                    }
                }
            });
        }
    });

    return new QzsjGwcmsg();

});